//
//  TotalViewController.m
//  DaDaBao
//
//  Created by User on 15/8/12.
//  Copyright (c) 2015年 User. All rights reserved.
//

#import "TotalViewController.h"
#import "HomePageViewController.h"
#import "ProjectViewController.h"
#import "OwnerViewController.h"
#import "MoreViewController.h"

@interface TotalViewController ()<UITabBarControllerDelegate>

@end

@implementation TotalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    HomePageViewController *homePageViewCon = [[HomePageViewController alloc]init];
    homePageViewCon.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页"  image:[UIImage imageNamed:@"home_page"] selectedImage:[UIImage imageNamed:@"selectedHome"]];
    
    ProjectViewController *projectViewCon = [[ProjectViewController alloc]init];
    projectViewCon.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"项目"  image:[UIImage imageNamed:@"project_list"] selectedImage:[UIImage imageNamed:@"selectedProduct"]];
    
    OwnerViewController *ownerViewCon = [[OwnerViewController alloc]init];
    ownerViewCon.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的"  image:[UIImage imageNamed:@"owner"] selectedImage:[UIImage imageNamed:@"selectedOwner"]];
    
    MoreViewController *moreViewCon = [[MoreViewController alloc]init];
    moreViewCon.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"更多"  image:[UIImage imageNamed:@"more"] selectedImage:[UIImage imageNamed:@"selectedMore"]];
    
    self.viewControllers = @[homePageViewCon, projectViewCon, ownerViewCon, moreViewCon];
    self.delegate = self;
    self.tabBar.tintColor = [UIColor hexStringToColor:COLOR_VALUE];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    if([viewController isKindOfClass:[OwnerViewController class]])
    {
        if([[NSUserDefaults standardUserDefaults] objectForKey:@"token"] != nil)
            return TRUE;
        else
        {
            LoginViewController *loginViewCon = [[LoginViewController alloc]init];
            [self presentViewController:loginViewCon animated:TRUE completion:^{}];
            return FALSE;
        }
            
    }
    return TRUE;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
